package com.qianyucc.blog.controller.plugins;

import cn.hutool.core.map.*;
import com.qianyucc.blog.mapper.*;
import com.qianyucc.blog.model.entity.*;
import com.qianyucc.blog.model.vo.*;
import io.swagger.annotations.*;
import lombok.extern.slf4j.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * @author lijing
 * @e-mail 1413979079@qq.com
 * @date 2020-01-09 14:25
 * @description 网站导航
 */
@Slf4j
@RestController
@RequestMapping("plugins")
public class WebSitesController {
    @Autowired
    private ConfigMapper configMapper;

    @ApiOperation("获取网站导航信息")
    @GetMapping("/websites")
    public Map<String, String> get() {
        ConfigDO configDO = configMapper.findByKey("websites");
        return MapUtil.of("content", configDO != null ? configDO.getValue() : "");
    }

    @ApiOperation("增加或更新网站导航信息")
    @PostMapping("/websites")
    public ResultVO post(@RequestBody ConfigDO configDO) {
        ConfigDO config = configMapper.findByKey(configDO.getKey());
        if (config != null) {
            configMapper.update(configDO);
        } else {
            configMapper.insert(configDO);
        }
        return ResultVO.ok("操作成功！");
    }
}
